#include <bits/stdc++.h>

using namespace std;

int main_57()
{
    int n,k,now_num=1;
    scanf("%d%d",&n,&k);
    queue<int> little_friends;
    for (int i=1;i<=n ;++i )
    {
        little_friends.push(i);
    }
    while (!little_friends.empty())
    {
        if (little_friends.size()==1)
        {
            printf("%d",little_friends.front());
            little_friends.pop();
        }
        else
        {
            if (now_num%k==0||now_num%10==k)
            {
                little_friends.pop();
            }
            else
            {
                little_friends.push(little_friends.front());
                little_friends.pop();
            }
        }
        ++now_num;
    }
    return 0;
}
